package com.chase.framerwork.interceptor;

import com.chase.framerwork.message.Message;
import com.chase.framerwork.message.MessageUtil;
import com.chase.framerwork.util.StringUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * 消息拦截器:未完成
 * 
 * @Author Chase
 * @Date 2013-11-10
 */
public class MessageInterceptor extends AbstractInterceptor
{
	private static final long serialVersionUID = 580284161351734164L;

	/**
	 * 消息Code
	 */
	private static final String MESSAGE_CODE = "messageCode";

	/**
	 * 消息Info
	 */
	private static final String MESSAGE_INFO = "messageInfo";

	@Override
	public String intercept(ActionInvocation invocation) throws Exception
	{
		String invoke = invocation.invoke();
		if (!MessageUtil.isEmpty())
		{
			Message message = MessageUtil.get();
			
			if (StringUtil.isNotEmpty(message.getCode()))
			{
				ActionContext.getContext().put(MESSAGE_CODE, message.getCode());
			}
			
			if (StringUtil.isNotEmpty(message.getInfo()))
			{
				ActionContext.getContext().put(MESSAGE_INFO, message.getInfo());	
			}
			
			MessageUtil.remove();
		}
		return invoke;
	}
}
